from django.template.loader import BaseLoader
from models import Template
from django.core.exceptions import ObjectDoesNotExist
from django.template import TemplateDoesNotExist

class Loader(BaseLoader):
    is_usable = True

    def load_template_source(self, template_name, template_dirs=None): #@UnusedVariable
        
        try:
            tpl = Template.objects.get( name__iexact=template_name )
            return ( tpl.content, 'db:'+tpl.name )
        except ObjectDoesNotExist:
            raise TemplateDoesNotExist
        
    load_template_source.is_usable = True
